package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划管理")
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping
    @ApiOperation(value = "查询所有护理计划")
    public ResponseResult getAll() {
        List<NursingPlanVo> nursingPlanVos = nursingPlanService.getAll();
        return ResponseResult.success(nursingPlanVos);
    }

    @PostMapping
    @ApiOperation(value = "添加护理计划")
    public ResponseResult addNursingPlan(@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.addNursingPlan(nursingPlanDto);
        return ResponseResult.success();
    }

    @GetMapping("/search")
    @ApiOperation(value = "条件分页查询")
    public ResponseResult<PageResponse<NursingPlanVo>> searchNation(@ApiParam(value = "护理计划名称") String name,
                                                                    @ApiParam(value = "状态：0-禁用，1-启用") Integer status,
                                                                    @ApiParam(value = "当前页码")
                                                                    @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                    @ApiParam(value = "每页显示数量")
                                                                    @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingPlanVo> result = nursingPlanService.getByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(result);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理计划")
    public ResponseResult getById(@PathVariable Long id) {
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        return ResponseResult.success(nursingPlanVo);
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "修改护理计划")
    public ResponseResult update(@PathVariable Long id ,@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.update(id,nursingPlanDto);
        return ResponseResult.success();
    }
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除护理计划")
    public ResponseResult deleteById(@PathVariable Long id) {
        nursingPlanService.deleteById(id);
        return ResponseResult.success();
    }
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "修改护理计划状态")
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        nursingPlanService.updateStatus(id, status);
        return ResponseResult.success();
    }
}
